package org.sklse.learningassistant.service;

import org.sklse.learningassistant.bean.Mistake;
import org.sklse.learningassistant.repository.MistakeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.Date;

@Transactional
@Service
public class MistakeService {

    @Autowired
    private MistakeRepository mistakeRepository;

    @Autowired
    private ImageService imageService;

    public Mistake findById(String id){
        return mistakeRepository.findByMisId(id);
    }

    public Mistake save(Mistake mistake){
        Mistake mistake1 = mistakeRepository.save(mistake);
        System.out.println(mistake1.getMisId());
        System.out.println(mistake1.getQuesPicUrl());
        String quesPicurl=imageService.uploadImage(mistake1.getQuesPicUrl(),"mistake"+ mistake1.getMisId());
        mistake1.setQuesPicUrl(quesPicurl);
        mistake1.setBulidTime(new Date().toString());
        return mistakeRepository.save(mistake1);
    }
}
